package com.liyuxiang.controller;

import com.liyuxiang.pojo.vo.ArticleVo;
import com.liyuxiang.service.ArticleService;
import com.liyuxiang.vm.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList() {
        //查询热门文章并返回
        return articleService.getHotArticleList();
    }

    @GetMapping("/articleList")
    public ResponseResult articleList(@RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum, @RequestParam("pageSize") Integer pageSize, @RequestParam(value = "categoryId", required = false) Long categoryId) {
        return articleService.articleList(pageNum, pageSize, categoryId);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleById(@PathVariable("id") @Validated Long id) {
        return articleService.getArticleById(id);
    }

}
